from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task

# If you want to run a snippet of code before or after the crew starts,
# you can use the @before_kickoff and @after_kickoff decorators
# https://docs.crewai.com/concepts/crews#example-crew-class-with-decorators


@CrewBase
class DevCrew:
   
   

    
    @agent
    def junior_python_developer(self) -> Agent:
        return Agent(
            role="Junior python developer",
            goal="write python code solution  without python type hints and pydocs. for this problem '{problem}'",
            backstory="You have 3 years python web development exprience, you know how to use flask, django"
        )
    
    @agent
    def senior_python_developer(self) -> Agent:
        return Agent(
            role="Senior python developer",
            goal="""review the python code generated by junior_python_developer for this problem '{problem}' 
                    apply python type hints
                    apply pydocs
                    write 3 pytest tests for the code""",
            backstory="""You have 20 years exprience in Machine learning, Deep Learning, Generative AI, Agentic Agentic
                        you have good commands on crewai, langgraph and auto gent"""
        )

    @task
    def write_code(self) -> Task:
        return Task(
            description="you have to write python solution without python type hints and pydocs for this problem '{problem}'",
            expected_output="return python code only",
            agent=self.junior_python_developer()
        )
    
    @task
    def review_code(self) -> Task:
        return Task(
            description="""You have to review the python code generated by junior_python_developer for this problem '{problem}' 
    optimize the code
    apply python type hints
    apply pydocs
    write 3 pytest tests for the code""",
            expected_output="return python code only",
            agent=self.senior_python_developer()
        )

    @crew
    def crew(self) -> Crew:
        """Creates the Research Crew"""
        # To learn how to add knowledge sources to your crew, check out the documentation:
        # https://docs.crewai.com/concepts/knowledge#what-is-knowledge

        return Crew(
            agents=self.agents,  # Automatically created by the @agent decorator
            tasks=self.tasks,  # Automatically created by the @task decorator
            process=Process.sequential,
            verbose=True,
        )
